
# 用python操作数据库，要用到pymysql
# import   pymysql
# db=pymysql.Connect(host="192.168.0.75",user="root",password="123456",database="cd20",port=3306)
# cursor=db.cursor()    #游标，用来执行数据库命令，存储数据库返回的结果
# cursor.execute('select * from b1')  #excute执行命令
# one=cursor.fetchone()        #取出游标中第一行数据
# all=cursor.fetchall()       #取出游标中全部的数据
# print(one)   #(1, 'zhang', 15174304291, 'nan')
# print(all)   #((2, 'li', 15174304281, 'nv'), (3, 'liu', 15174307291, 'nan'), (4, 'zhao', 15174306291, 'nv'))
# cursor.execute("insert into b1 values(5,'tian',15174305863,'nan')")
#
# db.commit()


import pymysql
class Db_unit():
    def  __init__(self,host,password,user,port,database):
        self.host=host
        self.password=password
        self.user=user
        self.database=database
        self.port=port
        self.db=pymysql.Connect(host=self.host,user=self.user,port=self.port,password=self.password,database=self.database)
    def  select_sql(self,sql):
        cursor=self.db.cursor()
        cursor.execute(sql)
        all=cursor.fetchall()
        return (all)
    def  delete_sql(self,sql,select_sql):
        cursor=self.db.cursor()
        cursor.execute(sql)
        self.select_sql(select_sql)
    def  insert_sql(self,sql,select_sql):
        cursor=self.db.cursor()
        cursor.execute(sql)
        self.select_sql(select_sql)
    def commit_sql(self):
        self.db.commit()

# if __name__ == '__main__':
#     db=Db_unit("192.168.0.75","123456","root",3306,"cd20")
    # # db.insert_sql("insert into b2 values ('5','90','89');","select * from b2;")
    # # db.commit_sql(
    #
    # # db.select_sql("select * from b2;")
    # #
    # # db.insert_sql("insert into b2 values ('6','98','96');","select * from b2;")
    #
    # db.delete_sql("delete from b2 where sid=6","select * from b2")
    # db.commit_sql()



































































